package com.xdf.data_transmitter.controller;

import com.xdf.data_transmitter.utils.DataTransmitter;
import com.xdf.data_transmitter.utils.JsonResult;
import com.xdf.data_transmitter.utils.TestAsync;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
@RequestMapping("/test")
@Slf4j
public class TestController {
    @Autowired
    private DataTransmitter dataTransmitter;

    @Autowired
    private TestAsync testAsync;

    @GetMapping("/uploadProcess")
    public JsonResult uploadProcess(){
        log.info("进入测试控制器的方法：uploadProcess");
        dataTransmitter.uploadProcess();
        log.info("退出测试控制器的方法：uploadProcess");
        return JsonResult.ok();
    }

    @GetMapping("/jrk")
    public JsonResult uploadJrk(){
        dataTransmitter.uploadRoll();
        return JsonResult.ok();
    }

    @GetMapping("/testAsync")
    public JsonResult testAsync() throws InterruptedException {
        testAsync.goAsync();
        return JsonResult.ok("测试异步方法");
    }

    @GetMapping("/testSync")
    public JsonResult testSync() throws InterruptedException {
        testAsync.goSync();
        return JsonResult.ok("测试同步方法");
    }

    @GetMapping("/testAsyncLocal")
    public JsonResult testAsyncLocal() throws InterruptedException {
        testAsync.methodA();
        testAsync.methodBAsync();
        testAsync.methodC();
        return JsonResult.ok("测试异步方法");
    }
}
